package health_system.health_system.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import health_system.health_system.entity.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserDTO {
    private Long id;
    private String username;
    private String fullName;
    private String avatarUrl;
    private String email;
    private String phoneNumber;
    private User.Gender gender;
    private LocalDate dateOfBirth;
    private String bio;
    
//    // 用户权限标记
//    private boolean admin;
//    private boolean moderator;
//    private boolean active;
    
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    
    // Additional fields for social media features
    private int followersCount;
    private int followingCount;
    private int postsCount;
    private boolean verified;
    private boolean followed;  // Whether the current user follows this user
    
    public static UserDTO fromEntity(User user) {
        if (user == null) {
            return null;
        }
        
        return UserDTO.builder()
                .id(user.getId())
                .username(user.getUsername())
                .fullName(user.getFullName())
                .avatarUrl(user.getAvatarUrl())
                .email(user.getEmail())
                .phoneNumber(user.getPhoneNumber())
                .gender(user.getGender())
                .dateOfBirth(user.getDateOfBirth())
                .bio(user.getBio())
//                .admin(user.isAdmin())
//                .moderator(user.isModerator())
//                .active(user.isActive())
                .createdAt(user.getCreatedAt())
                .updatedAt(user.getUpdatedAt())
                .followersCount(user.getFollowersCount())
                .followingCount(user.getFollowingCount())
                .postsCount(user.getPostsCount())
                .verified(user.isVerified())
                .followed(user.isFollowed())
                .build();
    }
    
    public static UserDTO fromEntityBasic(User user) {
        if (user == null) {
            return null;
        }
        
        return UserDTO.builder()
                .id(user.getId())
                .username(user.getUsername())
                .fullName(user.getFullName())
                .avatarUrl(user.getAvatarUrl())
                .build();
    }
} 